package club.haomoon.boss.service.impl.admin;

import club.haomoon.boss.service.admin.IAdminService;
import club.haomoon.boss.service.admin.IAuthService;
import club.haomoon.boss.vo.system.SystemAuthAdminDetailVo;
import club.haomoon.core.mapper.system.SystemMenuDataMapper;
import club.haomoon.core.mapper.system.SystemRoleMenuDataMapper;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * -------------------------
 * @Description: 权限功能类
 * @Author: Wangjianwei
 * @Date: 2025/02/17 17:17
 * -------------------------
 */
@Service
public class AuthServiceImpl implements IAuthService {

    @Resource
    IAdminService iAdminService;

    @Resource
    SystemMenuDataMapper systemMenuDataMapper;

    @Resource
    SystemRoleMenuDataMapper systemRoleMenuDataMapper;

    @Override
    public List<String> getBtnAuthByRoleId(Integer adminId) {
        List<String> ret = new ArrayList<String>();
        SystemAuthAdminDetailVo admin = iAdminService.detail(adminId);
        if (admin.getRoot().equals(1)) {
            ret.add("*");
            return ret;
        } else {
            List<Integer> menuIds = systemRoleMenuDataMapper.getMenuIds(adminId);
            ret = this.systemMenuDataMapper.getPerms(menuIds);
        }
        return ret;
    }
}
